﻿using System;
using System.Collections;
using System.Text;
using System.Data;
using System.Security.Cryptography;
using PlugNT.Safe;
using PlugNT.Database;
using PlugNT.Custom;
using PlugNT.Cms.Model;

namespace PlugNT.Cms.BLL
{
    public class Feedback
    {

        private static readonly PlugNT.Cms.DAL.Feedback dal = new PlugNT.Cms.DAL.Feedback();



        /// <summary>
        /// 根据id获取模型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FeedbackInfo GetFeedbackInfo(int id)
        {
            return dal.GetFeedbackInfo(id);
        }



        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(FeedbackInfo model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(FeedbackInfo model)
        {
            return dal.Update(model);
        }


        public bool UpdateLocked(int id, bool locked)
        {
            return dal.UpdateLocked(id, locked);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }


        public DataTable GetList(int sysModelId, string andWhere)
        {
            return dal.GetList(sysModelId, andWhere);
        }



        /// <summary>
        /// 得到列表(后台)
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currPage"></param>
        /// <param name="keyword"></param>
        /// <param name="isexact"></param>
        /// <param name="locked"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetList(int sysModelId, int pageSize, int currPage, string keyword, bool isexact, bool locked, out int recordCount)
        {
            StringBuilder andWhere = new StringBuilder();
            //标题或ID
            if (keyword != "")
            {
                if (isexact)
                {
                    andWhere.Append(" and [title]='" + StringHelper.SqlFilter(keyword) + "'");
                }
                else
                {
                    andWhere.Append(" and [title] like '%" + StringHelper.SqlFilter(keyword) + "%'");
                }

            }
            //是否锁定
            if (locked)
            {
                andWhere.Append(" and [locked]=1 ");
            }
            recordCount = dal.GetCount(sysModelId ,andWhere.ToString());
            return dal.GetList(sysModelId , pageSize, currPage, andWhere.ToString());
        }


        /// <summary>
        /// 得到列表(前台)
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currPage"></param>
        /// <param name="locked">-1为全部，0为假，1为真</param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetList(int sysModelId, int pageSize, int currPage, int locked, out int recordCount)
        {
            StringBuilder andWhere = new StringBuilder();
            //是否锁定
            if (locked != -1)
            {
                andWhere.Append(" and [locked]=" + (locked == 1 ? "1" : "0"));
            }
            recordCount = dal.GetCount(sysModelId, andWhere.ToString());
            return dal.GetList(sysModelId , pageSize, currPage, andWhere.ToString());
        }





    }
}
